<template>
  <div>
    <h2>注册页面</h2>
    <table>
      <tr>
        <td>用户名</td>
        <td>
          <input type="text" v-model="state.Uname" />
        </td>
      </tr>
      <tr>
        <td>密码</td>
        <td>
          <input type="text" v-model="state.Upwd" />
        </td>
      </tr>
      <tr>
        <td><input type="button" value="注册" @click="register" /></td>
        <td></td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import router from '@/router';
import axios from 'axios';
import { reactive, toRefs } from 'vue';
let data = reactive({
  state: {
    Uname: '',
    Upwd: ''
  }
});
let { state } = toRefs(data);
function register() {
  axios({
    url: 'http://localhost:62015/api/User/PostUserAdd',
    method: 'post',
    data: state.value
  })
    .then((res) => {
      console.log(res);
      if (res.data.data > 0) {
        alert('注册成功');
        router.push('/login');
      } else {
        alert('注册失败');
        return;
      }
    })
    .catch((err) => {
      console.log(err);
    });
}
</script>

<style scoped></style>
